#include "Game.h"
#include "StateMangager.h"
#include "Device.h"
#include "FrameController.h"


Game::Game()
{
}

Game::~Game()
{
}


void Game::pause()
{
	m_eStatus = EGSTATUS_PAUSED;
}

void Game::render()
{
	StateMangager::getInstance()->render();
}

void Game::update(float dt)
{
	switch (m_eStatus)
	{
	case EGSTATUS_INIT:
		this->init();
		m_eStatus = EGSTATUS_RUNNING;
		break;
	case EGSTATUS_RUNNING:
	case EGSTATUS_PAUSED:
		FrameController::getInstance()->startTimer();
		StateMangager::getInstance()->update(m_eStatus == EGSTATUS_PAUSED, dt);
		FrameController::getInstance()->endTimer();
		break;
	case EGSTATUS_EXIT:
		//force clean up current state
		StateMangager::getInstance()->switchState(0);
		StateMangager::getInstance()->update(false, dt);
		destroy();
		break;
	default:
		break;
	}
}

void Game::resume()
{
	m_eStatus = EGSTATUS_RUNNING;
}

void Game::exit()
{
	m_eStatus = EGSTATUS_EXIT;
}